import request from '@/utils/request'
import service from '@/api/config/const'
import { paramToString, update, getCondition } from '@/utils/param'

const baseUrl = service.upms
export function addSystem(system) {
  return request.post(baseUrl + '/upmsSystem', paramToString(system))
}

export function getSystem(id) {

}

/**
 * 按条件分页查询
 * @param system
 * @param pageNum
 * @param pageSize
 * @param orderBy
 */
export function getSystemByPage(system, pageNum, pageSize, orderBy) {
  const data = {}
  if (system) {
    getCondition(data, system, ['name', 'route', 'basepath'])
  }
  pageNum == null ? '' : data.pageNum = pageNum
  pageSize == null ? '' : data.pageSize = pageSize
  orderBy == null ? '' : data.orderBy = orderBy
  return request.get(baseUrl + '/upmsSystem/getPageByCondition?' + paramToString(data))
}

/**
 * delete请求传递参数和post,put不一样
 * @param id
 * @returns {boolean|*}
 */
export function deleteSystem(id) {
  const data = {
    ids: id
  }
  return request.delete(baseUrl + '/upmsSystem?' + paramToString(data))
}

export function editSystem(system) {
  const data = {}
  update(data, system)
  return request.put(baseUrl + '/upmsSystem/', paramToString(data))
}
